import { addLog, delLog, findLog } from '@renderer/apis/logAPI'
import { ref } from 'vue'

export default () => {
  const logs = ref<logModel[]>([])
  const log = ref<logModel>()

  const all = async () => {
    const data = (await window.api.sql('select * from logs order by date desc', 'findAll')) as any
    logs.value = data
  }

  const find = async (id: number) => {
    const { data } = (await findLog(id)) as any
    log.value = data
  }

  const add = async (data: logModel) => {
    return await addLog(data)
  }

  const del = async (id: number) => {
    await delLog(id)
  }
  return { add, all, find, del, log, logs }
}
